var Admin = function(){
	var row_template =
			'<tr id="row_{userid}">\
	   <td class="t_c">\
		  <input type="checkbox" class="checkbox_style" value="{userid}" />\
	   </td>\
	   <td class="t_r">{userid}</td>\
	   <td><a>{username}</a></td>\
	   <td class="t_c">{name}</td>\
	   <td>{email}</td>\
	   <td class="t_c">{sextext}</td>\
	   <td class="t_c">{state}</td>\
	   <td class="t_c">\
		  <img class="manage edit" height="16" width="16" alt="编辑" src="admin/images/edit.gif"/>\
		  <img class="manage delete" height="16" width="16" alt="删除" src="admin/images/delete.gif"/>\
	   </td>\
   </tr>',
		pagePrivTemplate = '\
<tr id="pagepriv_{pageid}">\
	<td class="t_l">\
		<label><input type="checkbox" class="checkbox_style" name="pageid[]" value="{pageid}" /> {name}</label>\
	</td>\
</tr>',
		init_row_event = function(id, tr){
			tr.find('>td>img.edit').click(function(){
				a.edit(id, tr);
			});
			tr.find('>td>img.delete').click(function(){
				a.del(id);
			});
		},
		editUrl,delUrl,addUrl,
		a = {
			table:null,
			init:function(baseUrl, pageSize){
				editUrl = baseUrl+'&a=edit';
				addUrl = baseUrl+'&a=add';
				delUrl = baseUrl+'&a=delete';
				a.table = new ct.table('#item_list',{
					pageSize: pageSize,
					dblclickHandler : a.edit,
					rowCallback : init_row_event,
					template : row_template,
					baseUrl : baseUrl+'&a=page'
				});
				a.table.load();
			},
			edit:function(id, tr){
				var url = editUrl+'&userid='+id;
				tr.trigger('check');
				ct.form('编辑管理员', url, 420, 400, function(json){
					if (json.state) {
						a.table.updateRow(id, json.data);
						return true;
					}
				},function(form, dialog){
					var divs = dialog.find('div.part');
					dialog.find('div.tabs>ul').tabnav({
						dataType:null,
						forceFocus:true,
						focused:function(li){
							divs.hide();
							divs.eq(li.attr('index')).show();
						}
					});
				},function(form, dialog, options) {
				});
			},
			add:function(){
				ct.form('添加管理员',addUrl,420, 400,function(json){
					if (json.state) {
						a.table.addRow(json.data);
						ct.tips('添加管理员成功','success');
						return true;
					} else {
                        ct.error(json.error);
                        return false;
                    }
				},function(form,dialog){
					var divs = dialog.find('div.part');
					dialog.find('div.tabs>ul').tabnav({
						dataType:null,
						forceFocus:true,
						focused:function(li){
							divs.hide();
							divs.eq(li.attr('index')).show();
						}
					});
				},function(form, dialog, options) {
				});
			},
			del:function(id){
				var msg;
				if (id === undefined)
				{
					id = a.table.checkedIds();
					if (!id.length)
					{
						ct.warn('请选中要删除项');
						return;
					}
					msg = '确定删除选中的<b style="color:red">'+id.length+'</b>条记录吗？';
				}
				else
				{
					msg = '确定删除编号为<b style="color:red">'+id+'</b>的记录吗？';
				}
				ct.confirm(msg,function(){
					$.post(delUrl,'id='+id,
						function(json){
							json.state
								? (ct.warn('删除完毕'), a.table.deleteRow(id))
								: ct.warn(json.error);
						},'json');
				});
			},
			score : function(id){
				ct.iframe({title:'?app=system&controller=score&action=editor&userid='+id,width:570,height:'auto'});
			}
		};
	return a;
}();